package eu.runelord.wjug.singleton;

public class Example2 {

	public static void main(String[] args) {
		ISingleton s1 = SingletonFactory.getINSTANCE();
		s1.setWorld("world");
		s1.sayHello();
		ISingleton s2 = SingletonFactory.getINSTANCE();
		s2.sayHello();
	}
}

class SingletonFactory {
	private static ISingleton singleton;

	public static ISingleton getINSTANCE() {
		if (singleton == null) {
			singleton = new ISingleton() {
				private String world = "";

				@Override
				public String getWorld() {

					return world;
				}

				@Override
				public void sayHello() {
					System.out.println("Hello " + world);

				}

				@Override
				public void setWorld(String world) {
					this.world = world;

				}

			};
		}
		return singleton;
	}
}